﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Edge.Business.Domain.Application;
using Edge.Common.Services;
using Edge.Common.Utils;
using Shop.Business.Domain.Customers;
using Shop.Business.Domain.Orders;

namespace Shop.Web.Controls
{
    public partial class Delivery_Type : System.Web.UI.UserControl
    {
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            Customer customer = Locator.GetService<IContextObjects>().Get<CustomerHolder>().Object;
            Order draftOrder = Locator.GetService<IOrderManager>().GetOrderWithStatus(customer, OrderStatus.Draft);
            List<DeliveryType> deliveryTypes = CollectionsUtils.Reverse(Locator.GetService<IDeliveryTypeManager>().FindAll());
            switch (draftOrder.CustomerAddress.City.ToLower())
            {
                case "ижевск":
                    deliveryTypes = CollectionsUtils.Reverse(deliveryTypes.Where(dt => dt.Name != "Почта России"));
                    break;
                default:
                    deliveryTypes = CollectionsUtils.Reverse(deliveryTypes.Where(dt => dt.Name == "Почта России"));
                    break;
            }
            lblAddresName.Text = draftOrder.CustomerAddress.Name;
            rprDeliveryType.DataSource = deliveryTypes;
            rprDeliveryType.DataBind();
            base.OnPreRender(e);
        }
    }
}